
(function(e) {
    e.jgrid.extend({
        groupingSetup: function() {
            return this.each(function() {
                var a = this.p.groupingView;
                if (a !== null && (typeof a === "object" || e.isFunction(a))) if (a.groupField.length) {
                    if (typeof a.visibiltyOnNextGrouping == "undefined") a.visibiltyOnNextGrouping = [];
                    for (var c = 0; c < a.groupField.length; c++) {
                        a.groupOrder[c] || (a.groupOrder[c] = "asc");
                        a.groupText[c] || (a.groupText[c] = "{0}");
                        if (typeof a.groupColumnShow[c] != "boolean") a.groupColumnShow[c] = true;
                        if (typeof a.groupSummary[c] != "boolean") a.groupSummary[c] = false;
                        if (a.groupColumnShow[c] === true) {
                            a.visibiltyOnNextGrouping[c] = true;
                            e(this).jqGrid("showCol", a.groupField[c])
                        } else {
                            a.visibiltyOnNextGrouping[c] = e("#" + this.p.id + "_" + a.groupField[c]).is(":visible");
                            e(this).jqGrid("hideCol", a.groupField[c])
                        }
                        a.sortitems[c] = [];
                        a.sortnames[c] = [];
                        a.summaryval[c] = [];
                        if (a.groupSummary[c]) {
                            a.summary[c] = [];
                            for (var b = this.p.colModel,
                            d = 0,
                            g = b.length; d < g; d++) b[d].summaryType && a.summary[c].push({
                                nm: b[d].name,
                                st: b[d].summaryType,
                                v: ""
                            })
                        }
                    }
                    this.p.scroll = false;
                    this.p.rownumbers = false;
                    this.p.subGrid = false;
                    this.p.treeGrid = false;
                    this.p.gridview = true
                } else this.p.grouping = false;
                else this.p.grouping = false
            })
        },
        groupingPrepare: function(a, c, b, d) {
            this.each(function() {
                c[0] += "";
                var g = c[0].toString().split(" ").join(""),
                h = this.p.groupingView,
                f = this;
                if (b.hasOwnProperty(g)) b[g].push(a);
                else {
                    b[g] = [];
                    b[g].push(a);
                    h.sortitems[0].push(g);
                    h.sortnames[0].push(e.trim(c[0].toString()));
                    h.summaryval[0][g] = e.extend(true, [], h.summary[0])
                }
                h.groupSummary[0] && e.each(h.summaryval[0][g],
                function() {
                    this.v = e.isFunction(this.st) ? this.st.call(f, this.v, this.nm, d) : e(f).jqGrid("groupingCalculations." + this.st, this.v, this.nm, d)
                })
            });
            return b
        },
        groupingToggle: function(a) {
            this.each(function() {
                var c = this.p.groupingView,
                b = a.lastIndexOf("_"),
                d = a.substring(0, b + 1);
                b = parseInt(a.substring(b + 1), 10) + 1;
                var g = c.minusicon,
                h = c.plusicon,
                f = e("#" + a);
                f = f.length ? f[0].nextSibling: null;
                var k = e("#" + a + " span.tree-wrap-" + this.p.direction),
                l = false;
                if (k.hasClass(g)) {
                    if (c.showSummaryOnHide && c.groupSummary[0]) {
                        if (f) for (; f;) {
                            if (e(f).hasClass("jqfoot")) break;
                            e(f).hide();
                            f = f.nextSibling
                        }
                    } else if (f) for (; f;) {
                        if (e(f).attr("id") == d + String(b)) break;
                        e(f).hide();
                        f = f.nextSibling
                    }
                    k.removeClass(g).addClass(h);
                    l = true
                } else {
                    if (f) for (; f;) {
                        if (e(f).attr("id") == d + String(b)) break;
                        e(f).show();
                        f = f.nextSibling
                    }
                    k.removeClass(h).addClass(g)
                }
                e.isFunction(this.p.onClickGroup) && this.p.onClickGroup.call(this, a, l)
            });
            return false
        },
        groupingRender: function(a, c) {
            return this.each(function() {
                var b = this,
                d = b.p.groupingView,
                g = "",
                h = "",
                f, k = d.groupCollapse ? d.plusicon: d.minusicon,
                l,
                r,
                m;
                if (!d.groupDataSorted) {
                    d.sortitems[0].sort();
                    d.sortnames[0].sort();
                    if (d.groupOrder[0].toLowerCase() == "desc") {
                        d.sortitems[0].reverse();
                        d.sortnames[0].reverse()
                    }
                }
                k += " tree-wrap-" + b.p.direction;
                for (m = 0; m < c;) {
                    if (b.p.colModel[m].name == d.groupField[0]) {
                        r = m;
                        break
                    }
                    m++
                }
                e.each(d.sortitems[0],
                function(o, n) {
                    f = b.p.id + "ghead_" + o;
                    h = "<span style='cursor:pointer;' class='ui-icon " + k + "' onclick=\"jQuery('#" + b.p.id + "').jqGrid('groupingToggle','" + f + "');return false;\"></span>";
                    try {
                        l = b.formatter(f, d.sortnames[0][o], r, d.sortitems[0])
                    } catch(v) {
                        l = d.sortnames[0][o]
                    }
                    g += '<tr id="' + f + '" role="row" class= "ui-widget-content jqgroup ui-row-' + b.p.direction + '"><td colspan="' + c + '">' + h + e.jgrid.format(d.groupText[0], l, a[n].length) + "</td></tr>";
                    for (var i = 0; i < a[n].length; i++) g += a[n][i].join("");
                    if (d.groupSummary[0]) {
                        i = "";
                        if (d.groupCollapse && !d.showSummaryOnHide) i = ' style="display:none;"';
                        g += "<tr" + i + ' role="row" class="ui-widget-content jqfoot ui-row-' + b.p.direction + '">';
                        i = d.summaryval[0][n];
                        for (var p = b.p.colModel,
                        q, s = a[n].length, j = 0; j < c; j++) {
                            var t = "<td " + b.formatCol(j, 1, "") + ">&#160;</td>",
                            u = "{0}";
                            e.each(i,
                            function() {
                                if (this.nm == p[j].name) {
                                    if (p[j].summaryTpl) u = p[j].summaryTpl;
                                    if (this.st == "avg") if (this.v && s > 0) this.v /= s;
                                    try {
                                        q = b.formatter("", this.v, j, this)
                                    } catch(w) {
                                        q = this.v
                                    }
                                    t = "<td " + b.formatCol(j, 1, "") + ">" + e.jgrid.format(u, q) + "</td>";
                                    return false
                                }
                            });
                            g += t
                        }
                        g += "</tr>"
                    }
                });
                e("#" + b.p.id + " tbody:first").append(g);
                g = null
            })
        },
        groupingGroupBy: function(a, c) {
            return this.each(function() {
                if (typeof a == "string") a = [a];
                var b = this.p.groupingView;
                this.p.grouping = true;
                if (typeof b.visibiltyOnNextGrouping == "undefined") b.visibiltyOnNextGrouping = [];
                var d;
                for (d = 0; d < b.groupField.length; d++) ! b.groupColumnShow[d] && b.visibiltyOnNextGrouping[d] && e(this).jqGrid("showCol", b.groupField[d]);
                for (d = 0; d < a.length; d++) b.visibiltyOnNextGrouping[d] = e("#" + this.p.id + "_" + a[d]).is(":visible");
                this.p.groupingView = e.extend(this.p.groupingView, c || {});
                b.groupField = a;
                e(this).trigger("reloadGrid")
            })
        },
        groupingRemove: function(a) {
            return this.each(function() {
                if (typeof a == "undefined") a = true;
                this.p.grouping = false;
                if (a === true) {
                    for (var c = this.p.groupingView,
                    b = 0; b < c.groupField.length; b++) ! c.groupColumnShow[b] && c.visibiltyOnNextGrouping[b] && e(this).jqGrid("showCol", c.groupField);
                    e("tr.jqgroup, tr.jqfoot", "#" + this.p.id + " tbody:first").remove();
                    e("tr.jqgrow:hidden", "#" + this.p.id + " tbody:first").show()
                } else e(this).trigger("reloadGrid")
            })
        },
        groupingCalculations: {
            sum: function(a, c, b) {
                return parseFloat(a || 0) + parseFloat(b[c] || 0)
            },
            min: function(a, c, b) {
                if (a === "") return parseFloat(b[c] || 0);
                return Math.min(parseFloat(a), parseFloat(b[c] || 0))
            },
            max: function(a, c, b) {
                if (a === "") return parseFloat(b[c] || 0);
                return Math.max(parseFloat(a), parseFloat(b[c] || 0))
            },
            count: function(a, c, b) {
                if (a === "") a = 0;
                return b.hasOwnProperty(c) ? a + 1 : 0
            },
            avg: function(a, c, b) {
                return parseFloat(a || 0) + parseFloat(b[c] || 0)
            }
        }
    })
})(jQuery); 
(function(d) {
    d.jgrid.extend({
        setTreeNode: function(a, c) {
            return this.each(function() {
                var b = this;
                if (b.grid && b.p.treeGrid) for (var e = b.p.expColInd,
                g = b.p.treeReader.expanded_field,
                h = b.p.treeReader.leaf_field,
                f = b.p.treeReader.level_field,
                l = b.p.treeReader.icon_field,
                i = b.p.treeReader.loaded,
                j, o, n, k; a < c;) {
                    k = b.p.data[b.p._index[b.rows[a].id]];
                    if (b.p.treeGridModel == "nested") if (!k[h]) {
                        j = parseInt(k[b.p.treeReader.left_field], 10);
                        o = parseInt(k[b.p.treeReader.right_field], 10);
                        k[h] = o === j + 1 ? "true": "false";
                        b.rows[a].cells[b.p._treeleafpos].innerHTML = k[h]
                    }
                    j = parseInt(k[f], 10);
                    if (b.p.tree_root_level === 0) {
                        n = j + 1;
                        o = j
                    } else {
                        n = j;
                        o = j - 1
                    }
                    n = "<div class='tree-wrap tree-wrap-" + b.p.direction + "' style='width:" + n * 18 + "px;'>";
                    n += "<div style='" + (b.p.direction == "rtl" ? "right:": "left:") + o * 18 + "px;' class='ui-icon ";
                    if (k[i] !== undefined) k[i] = k[i] == "true" || k[i] === true ? true: false;
                    if (k[h] == "true" || k[h] === true) {
                        n += (k[l] !== undefined && k[l] !== "" ? k[l] : b.p.treeIcons.leaf) + " tree-leaf treeclick";
                        k[h] = true;
                        o = "leaf"
                    } else {
                        k[h] = false;
                        o = ""
                    }
                    k[g] = (k[g] == "true" || k[g] === true ? true: false) && k[i];
                    n += k[g] === false ? k[h] === true ? "'": b.p.treeIcons.plus + " tree-plus treeclick'": k[h] === true ? "'": b.p.treeIcons.minus + " tree-minus treeclick'";
                    n += "></div></div>";
                    d(b.rows[a].cells[e]).wrapInner("<span class='cell-wrapper" + o + "'></span>").prepend(n);
                    if (j !== parseInt(b.p.tree_root_level, 10))(k = (k = d(b).jqGrid("getNodeParent", k)) && k.hasOwnProperty(g) ? k[g] : true) || d(b.rows[a]).css("display", "none");
                    d(b.rows[a].cells[e]).find("div.treeclick").bind("click",
                    function(m) {
                        m = d(m.target || m.srcElement, b.rows).closest("tr.jqgrow")[0].id;
                        m = b.p._index[m];
                        if (!b.p.data[m][h]) if (b.p.data[m][g]) {
                            d(b).jqGrid("collapseRow", b.p.data[m]);
                            d(b).jqGrid("collapseNode", b.p.data[m])
                        } else {
                            d(b).jqGrid("expandRow", b.p.data[m]);
                            d(b).jqGrid("expandNode", b.p.data[m])
                        }
                        return false
                    });
                    b.p.ExpandColClick === true && d(b.rows[a].cells[e]).find("span.cell-wrapper").css("cursor", "pointer").bind("click",
                    function(m) {
                        m = d(m.target || m.srcElement, b.rows).closest("tr.jqgrow")[0].id;
                        var r = b.p._index[m];
                        if (!b.p.data[r][h]) if (b.p.data[r][g]) {
                            d(b).jqGrid("collapseRow", b.p.data[r]);
                            d(b).jqGrid("collapseNode", b.p.data[r])
                        } else {
                            d(b).jqGrid("expandRow", b.p.data[r]);
                            d(b).jqGrid("expandNode", b.p.data[r])
                        }
                        d(b).jqGrid("setSelection", m);
                        return false
                    });
                    a++
                }
            })
        },
        setTreeGrid: function() {
            return this.each(function() {
                var a = this,
                c = 0,
                b = false,
                e, g, h = [];
                if (a.p.treeGrid) {
                    a.p.treedatatype || d.extend(a.p, {
                        treedatatype: a.p.datatype
                    });
                    a.p.subGrid = false;
                    a.p.altRows = false;
                    a.p.pgbuttons = false;
                    a.p.pginput = false;
                    a.p.gridview = true;
                    if (a.p.rowTotal === null) a.p.rowNum = 1E4;
                    a.p.multiselect = false;
                    a.p.rowList = [];
                    a.p.expColInd = 0;
                    a.p.treeIcons = d.extend({
                        plus: "ui-icon-triangle-1-" + (a.p.direction == "rtl" ? "w": "e"),
                        minus: "ui-icon-triangle-1-s",
                        leaf: "ui-icon-radio-off"
                    },
                    a.p.treeIcons || {});
                    if (a.p.treeGridModel == "nested") a.p.treeReader = d.extend({
                        level_field: "level",
                        left_field: "lft",
                        right_field: "rgt",
                        leaf_field: "isLeaf",
                        expanded_field: "expanded",
                        loaded: "loaded",
                        icon_field: "icon"
                    },
                    a.p.treeReader);
                    else if (a.p.treeGridModel == "adjacency") a.p.treeReader = d.extend({
                        level_field: "level",
                        parent_id_field: "parent",
                        leaf_field: "isLeaf",
                        expanded_field: "expanded",
                        loaded: "loaded",
                        icon_field: "icon"
                    },
                    a.p.treeReader);
                    for (g in a.p.colModel) if (a.p.colModel.hasOwnProperty(g)) {
                        e = a.p.colModel[g].name;
                        if (e == a.p.ExpandColumn && !b) {
                            b = true;
                            a.p.expColInd = c
                        }
                        c++;
                        for (var f in a.p.treeReader) a.p.treeReader[f] == e && h.push(e)
                    }
                    d.each(a.p.treeReader,
                    function(l, i) {
                        if (i && d.inArray(i, h) === -1) {
                            if (l === "leaf_field") a.p._treeleafpos = c;
                            c++;
                            a.p.colNames.push(i);
                            a.p.colModel.push({
                                name: i,
                                width: 1,
                                hidden: true,
                                sortable: false,
                                resizable: false,
                                hidedlg: true,
                                editable: true,
                                search: false
                            })
                        }
                    })
                }
            })
        },
        expandRow: function(a) {
            this.each(function() {
                var c = this;
                if (c.grid && c.p.treeGrid) {
                    var b = d(c).jqGrid("getNodeChildren", a),
                    e = c.p.treeReader.expanded_field;
                    d(b).each(function() {
                        var g = d.jgrid.getAccessor(this, c.p.localReader.id);
                        d("#" + g, c.grid.bDiv).css("display", "");
                        this[e] && d(c).jqGrid("expandRow", this)
                    })
                }
            })
        },
        collapseRow: function(a) {
            this.each(function() {
                var c = this;
                if (c.grid && c.p.treeGrid) {
                    var b = d(c).jqGrid("getNodeChildren", a),
                    e = c.p.treeReader.expanded_field;
                    d(b).each(function() {
                        var g = d.jgrid.getAccessor(this, c.p.localReader.id);
                        d("#" + g, c.grid.bDiv).css("display", "none");
                        this[e] && d(c).jqGrid("collapseRow", this)
                    })
                }
            })
        },
        getRootNodes: function() {
            var a = [];
            this.each(function() {
                var c = this;
                if (c.grid && c.p.treeGrid) switch (c.p.treeGridModel) {
                case "nested":
                    var b = c.p.treeReader.level_field;
                    d(c.p.data).each(function() {
                        parseInt(this[b], 10) === parseInt(c.p.tree_root_level, 10) && a.push(this)
                    });
                    break;
                case "adjacency":
                    var e = c.p.treeReader.parent_id_field;
                    d(c.p.data).each(function() {
                        if (this[e] === null || String(this[e]).toLowerCase() == "null") a.push(this)
                    })
                }
            });
            return a
        },
        getNodeDepth: function(a) {
            var c = null;
            this.each(function() {
                if (this.grid && this.p.treeGrid) switch (this.p.treeGridModel) {
                case "nested":
                    c = parseInt(a[this.p.treeReader.level_field], 10) - parseInt(this.p.tree_root_level, 10);
                    break;
                case "adjacency":
                    c = d(this).jqGrid("getNodeAncestors", a).length
                }
            });
            return c
        },
        getNodeParent: function(a) {
            var c = null;
            this.each(function() {
                if (this.grid && this.p.treeGrid) switch (this.p.treeGridModel) {
                case "nested":
                    var b = this.p.treeReader.left_field,
                    e = this.p.treeReader.right_field,
                    g = this.p.treeReader.level_field,
                    h = parseInt(a[b], 10),
                    f = parseInt(a[e], 10),
                    l = parseInt(a[g], 10);
                    d(this.p.data).each(function() {
                        if (parseInt(this[g], 10) === l - 1 && parseInt(this[b], 10) < h && parseInt(this[e], 10) > f) {
                            c = this;
                            return false
                        }
                    });
                    break;
                case "adjacency":
                    var i = this.p.treeReader.parent_id_field,
                    j = this.p.localReader.id;
                    d(this.p.data).each(function() {
                        if (this[j] == a[i]) {
                            c = this;
                            return false
                        }
                    })
                }
            });
            return c
        },
        getNodeChildren: function(a) {
            var c = [];
            this.each(function() {
                if (this.grid && this.p.treeGrid) switch (this.p.treeGridModel) {
                case "nested":
                    var b = this.p.treeReader.left_field,
                    e = this.p.treeReader.right_field,
                    g = this.p.treeReader.level_field,
                    h = parseInt(a[b], 10),
                    f = parseInt(a[e], 10),
                    l = parseInt(a[g], 10);
                    d(this.p.data).each(function() {
                        parseInt(this[g], 10) === l + 1 && parseInt(this[b], 10) > h && parseInt(this[e], 10) < f && c.push(this)
                    });
                    break;
                case "adjacency":
                    var i = this.p.treeReader.parent_id_field,
                    j = this.p.localReader.id;
                    d(this.p.data).each(function() {
                        this[i] == a[j] && c.push(this)
                    })
                }
            });
            return c
        },
        getFullTreeNode: function(a) {
            var c = [];
            this.each(function() {
                var b;
                if (this.grid && this.p.treeGrid) switch (this.p.treeGridModel) {
                case "nested":
                    var e = this.p.treeReader.left_field,
                    g = this.p.treeReader.right_field,
                    h = this.p.treeReader.level_field,
                    f = parseInt(a[e], 10),
                    l = parseInt(a[g], 10),
                    i = parseInt(a[h], 10);
                    d(this.p.data).each(function() {
                        parseInt(this[h], 10) >= i && parseInt(this[e], 10) >= f && parseInt(this[e], 10) <= l && c.push(this)
                    });
                    break;
                case "adjacency":
                    if (a) {
                        c.push(a);
                        var j = this.p.treeReader.parent_id_field,
                        o = this.p.localReader.id;
                        d(this.p.data).each(function(n) {
                            b = c.length;
                            for (n = 0; n < b; n++) if (c[n][o] == this[j]) {
                                c.push(this);
                                break
                            }
                        })
                    }
                }
            });
            return c
        },
        getNodeAncestors: function(a) {
            var c = [];
            this.each(function() {
                if (this.grid && this.p.treeGrid) for (var b = d(this).jqGrid("getNodeParent", a); b;) {
                    c.push(b);
                    b = d(this).jqGrid("getNodeParent", b)
                }
            });
            return c
        },
        isVisibleNode: function(a) {
            var c = true;
            this.each(function() {
                if (this.grid && this.p.treeGrid) {
                    var b = d(this).jqGrid("getNodeAncestors", a),
                    e = this.p.treeReader.expanded_field;
                    d(b).each(function() {
                        c = c && this[e];
                        if (!c) return false
                    })
                }
            });
            return c
        },
        isNodeLoaded: function(a) {
            var c;
            this.each(function() {
                if (this.grid && this.p.treeGrid) {
                    var b = this.p.treeReader.leaf_field;
                    c = a !== undefined ? a.loaded !== undefined ? a.loaded: a[b] || d(this).jqGrid("getNodeChildren", a).length > 0 ? true: false: false
                }
            });
            return c
        },
        expandNode: function(a) {
            return this.each(function() {
                if (this.grid && this.p.treeGrid) {
                    var c = this.p.treeReader.expanded_field,
                    b = this.p.treeReader.parent_id_field,
                    e = this.p.treeReader.loaded,
                    g = this.p.treeReader.level_field,
                    h = this.p.treeReader.left_field,
                    f = this.p.treeReader.right_field;
                    if (!a[c]) {
                        var l = d.jgrid.getAccessor(a, this.p.localReader.id),
                        i = d("#" + l, this.grid.bDiv)[0],
                        j = this.p._index[l];
                        if (d(this).jqGrid("isNodeLoaded", this.p.data[j])) {
                            a[c] = true;
                            d("div.treeclick", i).removeClass(this.p.treeIcons.plus + " tree-plus").addClass(this.p.treeIcons.minus + " tree-minus")
                        } else {
                            a[c] = true;
                            d("div.treeclick", i).removeClass(this.p.treeIcons.plus + " tree-plus").addClass(this.p.treeIcons.minus + " tree-minus");
                            this.p.treeANode = i.rowIndex;
                            this.p.datatype = this.p.treedatatype;
                            this.p.treeGridModel == "nested" ? d(this).jqGrid("setGridParam", {
                                postData: {
                                    nodeid: l,
                                    n_left: a[h],
                                    n_right: a[f],
                                    n_level: a[g]
                                }
                            }) : d(this).jqGrid("setGridParam", {
                                postData: {
                                    nodeid: l,
                                    parentid: a[b],
                                    n_level: a[g]
                                }
                            });
                            d(this).trigger("reloadGrid");
                            a[e] = true;
                            this.p.treeGridModel == "nested" ? d(this).jqGrid("setGridParam", {
                                postData: {
                                    nodeid: "",
                                    n_left: "",
                                    n_right: "",
                                    n_level: ""
                                }
                            }) : d(this).jqGrid("setGridParam", {
                                postData: {
                                    nodeid: "",
                                    parentid: "",
                                    n_level: ""
                                }
                            })
                        }
                    }
                }
            })
        },
        collapseNode: function(a) {
            return this.each(function() {
                if (this.grid && this.p.treeGrid) {
                    var c = this.p.treeReader.expanded_field;
                    if (a[c]) {
                        a[c] = false;
                        c = d.jgrid.getAccessor(a, this.p.localReader.id);
                        c = d("#" + c, this.grid.bDiv)[0];
                        d("div.treeclick", c).removeClass(this.p.treeIcons.minus + " tree-minus").addClass(this.p.treeIcons.plus + " tree-plus")
                    }
                }
            })
        },
        SortTree: function(a, c, b, e) {
            return this.each(function() {
                if (this.grid && this.p.treeGrid) {
                    var g, h, f, l = [],
                    i = this,
                    j;
                    g = d(this).jqGrid("getRootNodes");
                    g = d.jgrid.from(g);
                    g.orderBy(a, c, b, e);
                    j = g.select();
                    g = 0;
                    for (h = j.length; g < h; g++) {
                        f = j[g];
                        l.push(f);
                        d(this).jqGrid("collectChildrenSortTree", l, f, a, c, b, e)
                    }
                    d.each(l,
                    function(o) {
                        var n = d.jgrid.getAccessor(this, i.p.localReader.id);
                        d("#" + i.p.id + " tbody tr:eq(" + o + ")").after(d("tr#" + n, i.grid.bDiv))
                    });
                    l = j = g = null
                }
            })
        },
        collectChildrenSortTree: function(a, c, b, e, g, h) {
            return this.each(function() {
                if (this.grid && this.p.treeGrid) {
                    var f, l, i, j;
                    f = d(this).jqGrid("getNodeChildren", c);
                    f = d.jgrid.from(f);
                    f.orderBy(b, e, g, h);
                    j = f.select();
                    f = 0;
                    for (l = j.length; f < l; f++) {
                        i = j[f];
                        a.push(i);
                        d(this).jqGrid("collectChildrenSortTree", a, i, b, e, g, h)
                    }
                }
            })
        },
        setTreeRow: function(a, c) {
            var b = false;
            this.each(function() {
                if (this.grid && this.p.treeGrid) b = d(this).jqGrid("setRowData", a, c)
            });
            return b
        },
        delTreeNode: function(a) {
            return this.each(function() {
                var c = this.p.localReader.id,
                b = this.p.treeReader.left_field,
                e = this.p.treeReader.right_field,
                g, h, f;
                if (this.grid && this.p.treeGrid) {
                    var l = this.p._index[a];
                    if (l !== undefined) {
                        g = parseInt(this.p.data[l][e], 10);
                        h = g - parseInt(this.p.data[l][b], 10) + 1;
                        l = d(this).jqGrid("getFullTreeNode", this.p.data[l]);
                        if (l.length > 0) for (var i = 0; i < l.length; i++) d(this).jqGrid("delRowData", l[i][c]);
                        if (this.p.treeGridModel === "nested") {
                            c = d.jgrid.from(this.p.data).greater(b, g, {
                                stype: "integer"
                            }).select();
                            if (c.length) for (f in c) c[f][b] = parseInt(c[f][b], 10) - h;
                            c = d.jgrid.from(this.p.data).greater(e, g, {
                                stype: "integer"
                            }).select();
                            if (c.length) for (f in c) c[f][e] = parseInt(c[f][e], 10) - h
                        }
                    }
                }
            })
        },
        addChildNode: function(a, c, b) {
            var e = this[0];
            if (b) {
                var g = e.p.treeReader.expanded_field,
                h = e.p.treeReader.leaf_field,
                f = e.p.treeReader.level_field,
                l = e.p.treeReader.parent_id_field,
                i = e.p.treeReader.left_field,
                j = e.p.treeReader.right_field,
                o = e.p.treeReader.loaded,
                n, k, m, r, p;
                n = 0;
                var s = c,
                t;
                if (typeof a === "undefined" || a === null) {
                    p = e.p.data.length - 1;
                    if (p >= 0) for (; p >= 0;) {
                        n = Math.max(n, parseInt(e.p.data[p][e.p.localReader.id], 10));
                        p--
                    }
                    a = n + 1
                }
                var u = d(e).jqGrid("getInd", c);
                t = false;
                if (c === undefined || c === null || c === "") {
                    s = c = null;
                    n = "last";
                    r = e.p.tree_root_level;
                    p = e.p.data.length + 1
                } else {
                    n = "after";
                    k = e.p._index[c];
                    m = e.p.data[k];
                    c = m[e.p.localReader.id];
                    r = parseInt(m[f], 10) + 1;
                    p = d(e).jqGrid("getFullTreeNode", m);
                    if (p.length) {
                        s = p = p[p.length - 1][e.p.localReader.id];
                        p = d(e).jqGrid("getInd", s) + 1
                    } else p = d(e).jqGrid("getInd", c) + 1;
                    if (m[h]) {
                        t = true;
                        m[g] = true;
                        d(e.rows[u]).find("span.cell-wrapperleaf").removeClass("cell-wrapperleaf").addClass("cell-wrapper").end().find("div.tree-leaf").removeClass(e.p.treeIcons.leaf + " tree-leaf").addClass(e.p.treeIcons.minus + " tree-minus");
                        e.p.data[k][h] = false;
                        m[o] = true
                    }
                }
                k = p + 1;
                b[g] = false;
                b[o] = true;
                b[f] = r;
                b[h] = true;
                if (e.p.treeGridModel === "adjacency") b[l] = c;
                if (e.p.treeGridModel === "nested") {
                    var q;
                    if (c !== null) {
                        h = parseInt(m[j], 10);
                        f = d.jgrid.from(e.p.data);
                        f = f.greaterOrEquals(j, h, {
                            stype: "integer"
                        });
                        f = f.select();
                        if (f.length) for (q in f) {
                            f[q][i] = f[q][i] > h ? parseInt(f[q][i], 10) + 2 : f[q][i];
                            f[q][j] = f[q][j] >= h ? parseInt(f[q][j], 10) + 2 : f[q][j]
                        }
                        b[i] = h;
                        b[j] = h + 1
                    } else {
                        h = parseInt(d(e).jqGrid("getCol", j, false, "max"), 10);
                        f = d.jgrid.from(e.p.data).greater(i, h, {
                            stype: "integer"
                        }).select();
                        if (f.length) for (q in f) f[q][i] = parseInt(f[q][i], 10) + 2;
                        f = d.jgrid.from(e.p.data).greater(j, h, {
                            stype: "integer"
                        }).select();
                        if (f.length) for (q in f) f[q][j] = parseInt(f[q][j], 10) + 2;
                        b[i] = h + 1;
                        b[j] = h + 2
                    }
                }
                if (c === null || d(e).jqGrid("isNodeLoaded", m) || t) {
                    d(e).jqGrid("addRowData", a, b, n, s);
                    d(e).jqGrid("setTreeNode", p, k)
                }
                m && !m[g] && d(e.rows[u]).find("div.treeclick").click()
            }
        }
    })
})(jQuery);
(function(b) {
    b.jgrid.extend({
        jqGridImport: function(a) {
            a = b.extend({
                imptype: "xml",
                impstring: "",
                impurl: "",
                mtype: "GET",
                impData: {},
                xmlGrid: {
                    config: "roots>grid",
                    data: "roots>rows"
                },
                jsonGrid: {
                    config: "grid",
                    data: "data"
                },
                ajaxOptions: {}
            },
            a || {});
            return this.each(function() {
                var d = this,
                c = function(f, g) {
                    var e = b(g.xmlGrid.config, f)[0],
                    h = b(g.xmlGrid.data, f)[0],
                    i;
                    if (xmlJsonClass.xml2json && b.jgrid.parse) {
                        e = xmlJsonClass.xml2json(e, " ");
                        e = b.jgrid.parse(e);
                        for (var l in e) if (e.hasOwnProperty(l)) i = e[l];
                        if (h) {
                            h = e.grid.datatype;
                            e.grid.datatype = "xmlstring";
                            e.grid.datastr = f;
                            b(d).jqGrid(i).jqGrid("setGridParam", {
                                datatype: h
                            })
                        } else b(d).jqGrid(i)
                    } else alert("xml2json or parse are not present")
                },
                j = function(f, g) {
                    if (f && typeof f == "string") {
                        var e = b.jgrid.parse(f),
                        h = e[g.jsonGrid.config];
                        if (e = e[g.jsonGrid.data]) {
                            var i = h.datatype;
                            h.datatype = "jsonstring";
                            h.datastr = e;
                            b(d).jqGrid(h).jqGrid("setGridParam", {
                                datatype: i
                            })
                        } else b(d).jqGrid(h)
                    }
                };
                switch (a.imptype) {
                case "xml":
                    b.ajax(b.extend({
                        url:
                        a.impurl,
                        type: a.mtype,
                        data: a.impData,
                        dataType: "xml",
                        complete: function(f, g) {
                            if (g == "success") {
                                c(f.responseXML, a);
                                b.isFunction(a.importComplete) && a.importComplete(f)
                            }
                        }
                    },
                    a.ajaxOptions));
                    break;
                case "xmlstring":
                    if (a.impstring && typeof a.impstring == "string") {
                        var k = b.jgrid.stringToDoc(a.impstring);
                        if (k) {
                            c(k, a);
                            b.isFunction(a.importComplete) && a.importComplete(k);
                            a.impstring = null
                        }
                        k = null
                    }
                    break;
                case "json":
                    b.ajax(b.extend({
                        url:
                        a.impurl,
                        type: a.mtype,
                        data: a.impData,
                        dataType: "json",
                        complete: function(f, g) {
                            if (g == "success") {
                                j(f.responseText, a);
                                b.isFunction(a.importComplete) && a.importComplete(f)
                            }
                        }
                    },
                    a.ajaxOptions));
                    break;
                case "jsonstring":
                    if (a.impstring && typeof a.impstring == "string") {
                        j(a.impstring, a);
                        b.isFunction(a.importComplete) && a.importComplete(a.impstring);
                        a.impstring = null
                    }
                }
            })
        },
        jqGridExport: function(a) {
            a = b.extend({
                exptype: "xmlstring",
                root: "grid",
                ident: "\t"
            },
            a || {});
            var d = null;
            this.each(function() {
                if (this.grid) {
                    var c = b.extend({},
                    b(this).jqGrid("getGridParam"));
                    if (c.rownumbers) {
                        c.colNames.splice(0, 1);
                        c.colModel.splice(0, 1)
                    }
                    if (c.multiselect) {
                        c.colNames.splice(0, 1);
                        c.colModel.splice(0, 1)
                    }
                    if (c.subGrid) {
                        c.colNames.splice(0, 1);
                        c.colModel.splice(0, 1)
                    }
                    c.knv = null;
                    if (c.treeGrid) for (var j in c.treeReader) if (c.treeReader.hasOwnProperty(j)) {
                        c.colNames.splice(c.colNames.length - 1);
                        c.colModel.splice(c.colModel.length - 1)
                    }
                    switch (a.exptype) {
                    case "xmlstring":
                        d = "<" + a.root + ">" + xmlJsonClass.json2xml(c, a.ident) + "</" + a.root + ">";
                        break;
                    case "jsonstring":
                        d = "{" + xmlJsonClass.toJson(c, a.root, a.ident, false) + "}";
                        if (c.postData.filters !== undefined) {
                            d = d.replace(/filters":"/, 'filters":');
                            d = d.replace(/}]}"/, "}]}")
                        }
                    }
                }
            });
            return d
        },
        excelExport: function(a) {
            a = b.extend({
                exptype: "remote",
                url: null,
                oper: "oper",
                tag: "excel",
                exportOptions: {}
            },
            a || {});
            return this.each(function() {
                if (this.grid) {
                    var d;
                    if (a.exptype == "remote") {
                        d = b.extend({},
                        this.p.postData);
                        d[a.oper] = a.tag;
                        d = jQuery.param(d);
                        d = a.url.indexOf("?") != -1 ? a.url + "&" + d: a.url + "?" + d;
                        window.location = d
                    }
                }
            })
        }
    })
})(jQuery);

var xmlJsonClass = {
    xml2json: function(a, b) {
        if (a.nodeType === 9) a = a.documentElement;
        var h = this.toJson(this.toObj(this.removeWhite(a)), a.nodeName, "\t");
        return "{\n" + b + (b ? h.replace(/\t/g, b) : h.replace(/\t|\n/g, "")) + "\n}"
    },
    json2xml: function(a, b) {
        var h = function(d, c, i) {
            var g = "",
            k, j;
            if (d instanceof Array) if (d.length === 0) g += i + "<" + c + ">__EMPTY_ARRAY_</" + c + ">\n";
            else {
                k = 0;
                for (j = d.length; k < j; k += 1) {
                    var l = i + h(d[k], c, i + "\t") + "\n";
                    g += l
                }
            } else if (typeof d === "object") {
                k = false;
                g += i + "<" + c;
                for (j in d) if (d.hasOwnProperty(j)) if (j.charAt(0) === "@") g += " " + j.substr(1) + '="' + d[j].toString() + '"';
                else k = true;
                g += k ? ">": "/>";
                if (k) {
                    for (j in d) if (d.hasOwnProperty(j)) if (j === "#text") g += d[j];
                    else if (j === "#cdata") g += "<![CDATA[" + d[j] + "]]\>";
                    else if (j.charAt(0) !== "@") g += h(d[j], j, i + "\t");
                    g += (g.charAt(g.length - 1) === "\n" ? i: "") + "</" + c + ">"
                }
            } else if (typeof d === "function") g += i + "<" + c + "><![CDATA[" + d + "]]\></" + c + ">";
            else {
                if (d === undefined) d = "";
                g += d.toString() === '""' || d.toString().length === 0 ? i + "<" + c + ">__EMPTY_STRING_</" + c + ">": i + "<" + c + ">" + d.toString() + "</" + c + ">"
            }
            return g
        },
        e = "",
        f;
        for (f in a) if (a.hasOwnProperty(f)) e += h(a[f], f, "");
        return b ? e.replace(/\t/g, b) : e.replace(/\t|\n/g, "")
    },
    toObj: function(a) {
        var b = {},
        h = /function/i;
        if (a.nodeType === 1) {
            if (a.attributes.length) {
                var e;
                for (e = 0; e < a.attributes.length; e += 1) b["@" + a.attributes[e].nodeName] = (a.attributes[e].nodeValue || "").toString()
            }
            if (a.firstChild) {
                var f = e = 0,
                d = false,
                c;
                for (c = a.firstChild; c; c = c.nextSibling) if (c.nodeType === 1) d = true;
                else if (c.nodeType === 3 && c.nodeValue.match(/[^ \f\n\r\t\v]/)) e += 1;
                else if (c.nodeType === 4) f += 1;
                if (d) if (e < 2 && f < 2) {
                    this.removeWhite(a);
                    for (c = a.firstChild; c; c = c.nextSibling) if (c.nodeType === 3) b["#text"] = this.escape(c.nodeValue);
                    else if (c.nodeType === 4) if (h.test(c.nodeValue)) b[c.nodeName] = [b[c.nodeName], c.nodeValue];
                    else b["#cdata"] = this.escape(c.nodeValue);
                    else if (b[c.nodeName]) if (b[c.nodeName] instanceof Array) b[c.nodeName][b[c.nodeName].length] = this.toObj(c);
                    else b[c.nodeName] = [b[c.nodeName], this.toObj(c)];
                    else b[c.nodeName] = this.toObj(c)
                } else if (a.attributes.length) b["#text"] = this.escape(this.innerXml(a));
                else b = this.escape(this.innerXml(a));
                else if (e) if (a.attributes.length) b["#text"] = this.escape(this.innerXml(a));
                else {
                    b = this.escape(this.innerXml(a));
                    if (b === "__EMPTY_ARRAY_") b = "[]";
                    else if (b === "__EMPTY_STRING_") b = ""
                } else if (f) if (f > 1) b = this.escape(this.innerXml(a));
                else for (c = a.firstChild; c; c = c.nextSibling) if (h.test(a.firstChild.nodeValue)) {
                    b = a.firstChild.nodeValue;
                    break
                } else b["#cdata"] = this.escape(c.nodeValue)
            }
            if (!a.attributes.length && !a.firstChild) b = null
        } else if (a.nodeType === 9) b = this.toObj(a.documentElement);
        else alert("unhandled node type: " + a.nodeType);
        return b
    },
    toJson: function(a, b, h, e) {
        if (e === undefined) e = true;
        var f = b ? '"' + b + '"': "",
        d = "\t",
        c = "\n";
        if (!e) c = d = "";
        if (a === "[]") f += b ? ":[]": "[]";
        else if (a instanceof Array) {
            var i, g, k = [];
            g = 0;
            for (i = a.length; g < i; g += 1) k[g] = this.toJson(a[g], "", h + d, e);
            f += (b ? ":[": "[") + (k.length > 1 ? c + h + d + k.join("," + c + h + d) + c + h: k.join("")) + "]"
        } else if (a === null) f += (b && ":") + "null";
        else if (typeof a === "object") {
            i = [];
            for (g in a) if (a.hasOwnProperty(g)) i[i.length] = this.toJson(a[g], g, h + d, e);
            f += (b ? ":{": "{") + (i.length > 1 ? c + h + d + i.join("," + c + h + d) + c + h: i.join("")) + "}"
        } else f += typeof a === "string" ? (b && ":") + '"' + a.replace(/\\/g, "\\\\").replace(/\"/g, '\\"') + '"': (b && ":") + '"' + a.toString() + '"';
        return f
    },
    innerXml: function(a) {
        var b = "";
        if ("innerHTML" in a) b = a.innerHTML;
        else {
            var h = function(e) {
                var f = "",
                d;
                if (e.nodeType === 1) {
                    f += "<" + e.nodeName;
                    for (d = 0; d < e.attributes.length; d += 1) f += " " + e.attributes[d].nodeName + '="' + (e.attributes[d].nodeValue || "").toString() + '"';
                    if (e.firstChild) {
                        f += ">";
                        for (d = e.firstChild; d; d = d.nextSibling) f += h(d);
                        f += "</" + e.nodeName + ">"
                    } else f += "/>"
                } else if (e.nodeType === 3) f += e.nodeValue;
                else if (e.nodeType === 4) f += "<![CDATA[" + e.nodeValue + "]]\>";
                return f
            };
            for (a = a.firstChild; a; a = a.nextSibling) b += h(a)
        }
        return b
    },
    escape: function(a) {
        return a.replace(/[\\]/g, "\\\\").replace(/[\"]/g, '\\"').replace(/[\n]/g, "\\n").replace(/[\r]/g, "\\r")
    },
    removeWhite: function(a) {
        a.normalize();
        var b;
        for (b = a.firstChild; b;) if (b.nodeType === 3) if (b.nodeValue.match(/[^ \f\n\r\t\v]/)) b = b.nextSibling;
        else {
            var h = b.nextSibling;
            a.removeChild(b);
            b = h
        } else {
            b.nodeType === 1 && this.removeWhite(b);
            b = b.nextSibling
        }
        return a
    }
};
function tableToGrid(n, o) {
    jQuery(n).each(function() {
        if (!this.grid) {
            jQuery(this).width("99%");
            var a = jQuery(this).width(),
            d = jQuery("tr td:first-child input[type=checkbox]:first", jQuery(this)),
            b = jQuery("tr td:first-child input[type=radio]:first", jQuery(this));
            d = d.length > 0;
            b = !d && b.length > 0;
            var l = d || b,
            c = [],
            g = [];
            jQuery("th", jQuery(this)).each(function() {
                if (c.length === 0 && l) {
                    c.push({
                        name: "__selection__",
                        index: "__selection__",
                        width: 0,
                        hidden: true
                    });
                    g.push("__selection__")
                } else {
                    c.push({
                        name: jQuery(this).attr("id") || jQuery.trim(jQuery.jgrid.stripHtml(jQuery(this).html())).split(" ").join("_"),
                        index: jQuery(this).attr("id") || jQuery.trim(jQuery.jgrid.stripHtml(jQuery(this).html())).split(" ").join("_"),
                        width: jQuery(this).width() || 150
                    });
                    g.push(jQuery(this).html())
                }
            });
            var f = [],
            h = [],
            i = [];
            jQuery("tbody > tr", jQuery(this)).each(function() {
                var j = {},
                e = 0;
                jQuery("td", jQuery(this)).each(function() {
                    if (e === 0 && l) {
                        var k = jQuery("input", jQuery(this)),
                        m = k.attr("value");
                        h.push(m || f.length);
                        k.is(":checked") && i.push(m);
                        j[c[e].name] = k.attr("value")
                    } else j[c[e].name] = jQuery(this).html();
                    e++
                });
                e > 0 && f.push(j)
            });
            jQuery(this).empty();
            jQuery(this).addClass("scroll");
            jQuery(this).jqGrid(jQuery.extend({
                datatype: "local",
                width: a,
                colNames: g,
                colModel: c,
                multiselect: d
            },
            o || {}));
            for (a = 0; a < f.length; a++) {
                b = null;
                if (h.length > 0) if ((b = h[a]) && b.replace) b = encodeURIComponent(b).replace(/[.\-%]/g, "_");
                if (b === null) b = a + 1;
                jQuery(this).jqGrid("addRowData", b, f[a])
            }
            for (a = 0; a < i.length; a++) jQuery(this).jqGrid("setSelection", i[a])
        }
    })
}; (function(a) {
    if (false) a.expr[":"].hidden = function(b) {//a.browser.msie && a.browser.version == 8
        return b.offsetWidth === 0 || b.offsetHeight === 0 || b.style.display == "none"
    };
    a.jgrid._multiselect = false;
    if (a.ui) if (a.ui.multiselect) {
        if (a.ui.multiselect.prototype._setSelected) {
            var q = a.ui.multiselect.prototype._setSelected;
            a.ui.multiselect.prototype._setSelected = function(b, h) {
                var c = q.call(this, b, h);
                if (h && this.selectedList) {
                    var f = this.element;
                    this.selectedList.find("li").each(function() {
                        a(this).data("optionLink") && a(this).data("optionLink").remove().appendTo(f)
                    })
                }
                return c
            }
        }
        if (a.ui.multiselect.prototype.destroy) a.ui.multiselect.prototype.destroy = function() {
            this.element.show();
            this.container.remove();
            a.Widget === undefined ? a.widget.prototype.destroy.apply(this, arguments) : a.Widget.prototype.destroy.apply(this, arguments)
        };
        a.jgrid._multiselect = true
    }
    a.jgrid.extend({
        sortableColumns: function(b) {
            return this.each(function() {
                function h() {
                    c.p.disableClick = true
                }
                var c = this,
                f = c.p.id;
                f = {
                    tolerance: "pointer",
                    axis: "x",
                    scrollSensitivity: "1",
                    items: ">th:not(:has(#jqgh_" + f + "_cb,#jqgh_" + f + "_rn,#jqgh_" + f + "_subgrid),:hidden)",
                    placeholder: {
                        element: function(g) {
                            return a(document.createElement(g[0].nodeName)).addClass(g[0].className + " ui-sortable-placeholder ui-state-highlight").removeClass("ui-sortable-helper")[0]
                        },
                        update: function(g, j) {
                            j.height(g.currentItem.innerHeight() - parseInt(g.currentItem.css("paddingTop") || 0, 10) - parseInt(g.currentItem.css("paddingBottom") || 0, 10));
                            j.width(g.currentItem.innerWidth() - parseInt(g.currentItem.css("paddingLeft") || 0, 10) - parseInt(g.currentItem.css("paddingRight") || 0, 10))
                        }
                    },
                    update: function(g, j) {
                        var i = a(j.item).parent();
                        i = a(">th", i);
                        var l = {},
                        m = c.p.id + "_";
                        a.each(c.p.colModel,
                        function(k) {
                            l[this.name] = k
                        });
                        var d = [];
                        i.each(function() {
                            var k = a(">div", this).get(0).id.replace(/^jqgh_/, "").replace(m, "");
                            k in l && d.push(l[k])
                        });
                        a(c).jqGrid("remapColumns", d, true, true);
                        a.isFunction(c.p.sortable.update) && c.p.sortable.update(d);
                        setTimeout(function() {
                            c.p.disableClick = false
                        },
                        50)
                    }
                };
                if (c.p.sortable.options) a.extend(f, c.p.sortable.options);
                else if (a.isFunction(c.p.sortable)) c.p.sortable = {
                    update: c.p.sortable
                };
                if (f.start) {
                    var e = f.start;
                    f.start = function(g, j) {
                        h();
                        e.call(this, g, j)
                    }
                } else f.start = h;
                if (c.p.sortable.exclude) f.items += ":not(" + c.p.sortable.exclude + ")";
                b.sortable(f).data("sortable").floating = true
            })
        },
        columnChooser: function(b) {
            function h(d, k) {
                if (d) if (typeof d == "string") a.fn[d] && a.fn[d].apply(k, a.makeArray(arguments).slice(2));
                else a.isFunction(d) && d.apply(k, a.makeArray(arguments).slice(2))
            }
            var c = this;
            if (!a("#colchooser_" + c[0].p.id).length) {
                var f = a('<div id="colchooser_' + c[0].p.id + '" style="position:relative;overflow:hidden"><div><select multiple="multiple"></select></div></div>'),
                e = a("select", f);
                b = a.extend({
                    width: 420,
                    height: 240,
                    classname: null,
                    done: function(d) {
                        d && c.jqGrid("remapColumns", d, true)
                    },
                    msel: "multiselect",
                    dlog: "dialog",
                    dlog_opts: function(d) {
                        var k = {};
                        k[d.bSubmit] = function() {
                            d.apply_perm();
                            d.cleanup(false)
                        };
                        k[d.bCancel] = function() {
                            d.cleanup(true)
                        };
                        return {
                            buttons: k,
                            close: function() {
                                d.cleanup(true)
                            },
                            modal: d.modal ? d.modal: false,
                            resizable: d.resizable ? d.resizable: true,
                            width: d.width + 20
                        }
                    },
                    apply_perm: function() {
                        a("option", e).each(function() {
                            this.selected ? c.jqGrid("showCol", g[this.value].name) : c.jqGrid("hideCol", g[this.value].name)
                        });
                        var d = [];
                        a("option:selected", e).each(function() {
                            d.push(parseInt(this.value, 10))
                        });
                        a.each(d,
                        function() {
                            delete i[g[parseInt(this, 10)].name]
                        });
                        a.each(i,
                        function() {
                            var k = parseInt(this, 10);
                            var p = d,
                            o = k;
                            if (o >= 0) {
                                var n = p.slice(),
                                r = n.splice(o, Math.max(p.length - o, o));
                                if (o > p.length) o = p.length;
                                n[o] = k;
                                d = n.concat(r)
                            } else d = void 0
                        });
                        b.done && b.done.call(c, d)
                    },
                    cleanup: function(d) {
                        h(b.dlog, f, "destroy");
                        h(b.msel, e, "destroy");
                        f.remove();
                        d && b.done && b.done.call(c)
                    },
                    msel_opts: {}
                },
                a.jgrid.col, b || {});
                if (a.ui) if (a.ui.multiselect) if (b.msel == "multiselect") {
                    if (!a.jgrid._multiselect) {
                        alert("Multiselect plugin loaded after jqGrid. Please load the plugin before the jqGrid!");
                        return
                    }
                    b.msel_opts = a.extend(a.ui.multiselect.defaults, b.msel_opts)
                }
                b.caption && f.attr("title", b.caption);
                if (b.classname) {
                    f.addClass(b.classname);
                    e.addClass(b.classname)
                }
                if (b.width) {
                    a(">div", f).css({
                        width: b.width,
                        margin: "0 auto"
                    });
                    e.css("width", b.width)
                }
                if (b.height) {
                    a(">div", f).css("height", b.height);
                    e.css("height", b.height - 10)
                }
                var g = c.jqGrid("getGridParam", "colModel"),
                j = c.jqGrid("getGridParam", "colNames"),
                i = {},
                l = [];
                e.empty();
                a.each(g,
                function(d) {
                    i[this.name] = d;
                    if (this.hidedlg) this.hidden || l.push(d);
                    else e.append("<option value='" + d + "' " + (this.hidden ? "": "selected='selected'") + ">" + j[d] + "</option>")
                });
                var m = a.isFunction(b.dlog_opts) ? b.dlog_opts.call(c, b) : b.dlog_opts;
                h(b.dlog, f, m);
                m = a.isFunction(b.msel_opts) ? b.msel_opts.call(c, b) : b.msel_opts;
                h(b.msel, e, m)
            }
        },
        sortableRows: function(b) {
            return this.each(function() {
                var h = this;
                if (h.grid) if (!h.p.treeGrid) if (a.fn.sortable) {
                    b = a.extend({
                        cursor: "move",
                        axis: "y",
                        items: ".jqgrow"
                    },
                    b || {});
                    if (b.start && a.isFunction(b.start)) {
                        b._start_ = b.start;
                        delete b.start
                    } else b._start_ = false;
                    if (b.update && a.isFunction(b.update)) {
                        b._update_ = b.update;
                        delete b.update
                    } else b._update_ = false;
                    b.start = function(c, f) {
                        a(f.item).css("border-width", "0px");
                        a("td", f.item).each(function(j) {
                            this.style.width = h.grid.cols[j].style.width
                        });
                        if (h.p.subGrid) {
                            var e = a(f.item).attr("id");
                            try {
                                a(h).jqGrid("collapseSubGridRow", e)
                            } catch(g) {}
                        }
                        b._start_ && b._start_.apply(this, [c, f])
                    };
                    b.update = function(c, f) {
                        a(f.item).css("border-width", "");
                        h.p.rownumbers === true && a("td.jqgrid-rownum", h.rows).each(function(e) {
                            a(this).html(e + 1 + (parseInt(h.p.page, 10) - 1) * parseInt(h.p.rowNum, 10))
                        });
                        b._update_ && b._update_.apply(this, [c, f])
                    };
                    a("tbody:first", h).sortable(b);
                    a("tbody:first", h).disableSelection()
                }
            })
        },
        gridDnD: function(b) {
            return this.each(function() {
                function h() {
                    var e = a.data(c, "dnd");
                    a("tr.jqgrow:not(.ui-draggable)", c).draggable(a.isFunction(e.drag) ? e.drag.call(a(c), e) : e.drag)
                }
                var c = this;
                if (c.grid) if (!c.p.treeGrid) if (a.fn.draggable && a.fn.droppable) {
                    a("#jqgrid_dnd").html() === null && a("body").append("<table id='jqgrid_dnd' class='ui-jqgrid-dnd'></table>");
                    if (typeof b == "string" && b == "updateDnD" && c.p.jqgdnd === true) h();
                    else {
                        b = a.extend({
                            drag: function(e) {
                                return a.extend({
                                    start: function(g, j) {
                                        if (c.p.subGrid) {
                                            var i = a(j.helper).attr("id");
                                            try {
                                                a(c).jqGrid("collapseSubGridRow", i)
                                            } catch(l) {}
                                        }
                                        for (i = 0; i < a.data(c, "dnd").connectWith.length; i++) a(a.data(c, "dnd").connectWith[i]).jqGrid("getGridParam", "reccount") == "0" && a(a.data(c, "dnd").connectWith[i]).jqGrid("addRowData", "jqg_empty_row", {});
                                        j.helper.addClass("ui-state-highlight");
                                        a("td", j.helper).each(function(m) {
                                            this.style.width = c.grid.headers[m].width + "px"
                                        });
                                        e.onstart && a.isFunction(e.onstart) && e.onstart.call(a(c), g, j)
                                    },
                                    stop: function(g, j) {
                                        if (j.helper.dropped && !e.dragcopy) {
                                            var i = a(j.helper).attr("id");
                                            a(c).jqGrid("delRowData", i)
                                        }
                                        for (i = 0; i < a.data(c, "dnd").connectWith.length; i++) a(a.data(c, "dnd").connectWith[i]).jqGrid("delRowData", "jqg_empty_row");
                                        e.onstop && a.isFunction(e.onstop) && e.onstop.call(a(c), g, j)
                                    }
                                },
                                e.drag_opts || {})
                            },
                            drop: function(e) {
                                return a.extend({
                                    accept: function(g) {
                                        if (!a(g).hasClass("jqgrow")) return g;
                                        g = a(g).closest("table.ui-jqgrid-btable");
                                        if (g.length > 0 && a.data(g[0], "dnd") !== undefined) {
                                            g = a.data(g[0], "dnd").connectWith;
                                            return a.inArray("#" + this.id, g) != -1 ? true: false
                                        }
                                        return false
                                    },
                                    drop: function(g, j) {
                                        if (a(j.draggable).hasClass("jqgrow")) {
                                            var i = a(j.draggable).attr("id");
                                            i = j.draggable.parent().parent().jqGrid("getRowData", i);
                                            if (!e.dropbyname) {
                                                var l = 0,
                                                m = {},
                                                d, k = a("#" + this.id).jqGrid("getGridParam", "colModel");
                                                try {
                                                    for (var p in i) {
                                                        if (i.hasOwnProperty(p) && k[l]) {
                                                            d = k[l].name;
                                                            m[d] = i[p]
                                                        }
                                                        l++
                                                    }
                                                    i = m
                                                } catch(o) {}
                                            }
                                            j.helper.dropped = true;
                                            if (e.beforedrop && a.isFunction(e.beforedrop)) {
                                                d = e.beforedrop.call(this, g, j, i, a("#" + c.id), a(this));
                                                if (typeof d != "undefined" && d !== null && typeof d == "object") i = d
                                            }
                                            if (j.helper.dropped) {
                                                var n;
                                                if (e.autoid) if (a.isFunction(e.autoid)) n = e.autoid.call(this, i);
                                                else {
                                                    n = Math.ceil(Math.random() * 1E3);
                                                    n = e.autoidprefix + n
                                                }
                                                a("#" + this.id).jqGrid("addRowData", n, i, e.droppos)
                                            }
                                            e.ondrop && a.isFunction(e.ondrop) && e.ondrop.call(this, g, j, i)
                                        }
                                    }
                                },
                                e.drop_opts || {})
                            },
                            onstart: null,
                            onstop: null,
                            beforedrop: null,
                            ondrop: null,
                            drop_opts: {
                                activeClass: "ui-state-active",
                                hoverClass: "ui-state-hover"
                            },
                            drag_opts: {
                                revert: "invalid",
                                helper: "clone",
                                cursor: "move",
                                appendTo: "#jqgrid_dnd",
                                zIndex: 5E3
                            },
                            dragcopy: false,
                            dropbyname: false,
                            droppos: "first",
                            autoid: true,
                            autoidprefix: "dnd_"
                        },
                        b || {});
                        if (b.connectWith) {
                            b.connectWith = b.connectWith.split(",");
                            b.connectWith = a.map(b.connectWith,
                            function(e) {
                                return a.trim(e)
                            });
                            a.data(c, "dnd", b);
                            c.p.reccount != "0" && !c.p.jqgdnd && h();
                            c.p.jqgdnd = true;
                            for (var f = 0; f < b.connectWith.length; f++) a(b.connectWith[f]).droppable(a.isFunction(b.drop) ? b.drop.call(a(c), b) : b.drop)
                        }
                    }
                }
            })
        },
        gridResize: function(b) {
            return this.each(function() {
                var h = this;
                if (h.grid && a.fn.resizable) {
                    b = a.extend({},
                    b || {});
                    if (b.alsoResize) {
                        b._alsoResize_ = b.alsoResize;
                        delete b.alsoResize
                    } else b._alsoResize_ = false;
                    if (b.stop && a.isFunction(b.stop)) {
                        b._stop_ = b.stop;
                        delete b.stop
                    } else b._stop_ = false;
                    b.stop = function(c, f) {
                        a(h).jqGrid("setGridParam", {
                            height: a("#gview_" + h.p.id + " .ui-jqgrid-bdiv").height()
                        });
                        a(h).jqGrid("setGridWidth", f.size.width, b.shrinkToFit);
                        b._stop_ && b._stop_.call(h, c, f)
                    };
                    b.alsoResize = b._alsoResize_ ? eval("(" + ("{'#gview_" + h.p.id + " .ui-jqgrid-bdiv':true,'" + b._alsoResize_ + "':true}") + ")") : a(".ui-jqgrid-bdiv", "#gview_" + h.p.id);
                    delete b._alsoResize_;
                    a("#gbox_" + h.p.id).resizable(b)
                }
            })
        }
    })
})(jQuery);
;(function($){
/**
 * jqGrid extension for manipulating columns properties
 * Piotr Roznicki roznicki@o2.pl
 * http://www.roznicki.prv.pl
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl-2.0.html
**/
$.jgrid.extend({
	setColumns : function(p) {
		p = $.extend({
			top : 0,
			left: 0,
			width: 200,
			height: 'auto',
			dataheight: 'auto',
			modal: false,
			drag: true,
			beforeShowForm: null,
			afterShowForm: null,
			afterSubmitForm: null,
			closeOnEscape : true,
			ShrinkToFit : false,
			jqModal : false,
			saveicon: [true,"left","ui-icon-disk"],
			closeicon: [true,"left","ui-icon-close"],
			onClose : null,
			colnameview : true,
			closeAfterSubmit : true,
			updateAfterCheck : false,
			recreateForm : false
		}, $.jgrid.col, p ||{});
		return this.each(function(){debugger
			var $t = this;
			if (!$t.grid ) { return; }
			var onBeforeShow = typeof p.beforeShowForm === 'function' ? true: false;
			var onAfterShow = typeof p.afterShowForm === 'function' ? true: false;
			var onAfterSubmit = typeof p.afterSubmitForm === 'function' ? true: false;			
			var gID = $t.p.id,
			dtbl = "ColTbl_"+gID,
			IDs = {themodal:'colmod'+gID,modalhead:'colhd'+gID,modalcontent:'colcnt'+gID, scrollelm: dtbl};
			if(p.recreateForm===true && $("#"+IDs.themodal).html() != null) {
				$("#"+IDs.themodal).remove();
			}
			if ( $("#"+IDs.themodal).html() != null ) {
				if(onBeforeShow) { p.beforeShowForm($("#"+dtbl)); }
				$.jgrid.viewModal("#"+IDs.themodal,{gbox:"#gbox_"+gID,jqm:p.jqModal, jqM:false, modal:p.modal});
				if(onAfterShow) { p.afterShowForm($("#"+dtbl)); }
			} else {
				var dh = isNaN(p.dataheight) ? p.dataheight : p.dataheight+"px";
				var formdata = "<div id='"+dtbl+"' class='formdata' style='width:100%;overflow:auto;position:relative;height:"+dh+";'>";
				formdata += "<table class='ColTable' cellspacing='1' cellpading='2' border='0'><tbody>";
				for(i=0;i<this.p.colNames.length;i++){
					if(!$t.p.colModel[i].hidedlg) { // added from T. Tomov
						formdata += "<tr><td style='white-space: pre;'><input type='checkbox' style='margin-right:5px;' id='col_" + this.p.colModel[i].name + "' class='cbox' value='T' " + 
						((this.p.colModel[i].hidden===false)?"checked":"") + "/>" +  "<label for='col_" + this.p.colModel[i].name + "'>" + this.p.colNames[i] + ((p.colnameview) ? " (" + this.p.colModel[i].name + ")" : "" )+ "</label></td></tr>";
					}
				}
				formdata += "</tbody></table></div>"
				var bS  = !p.updateAfterCheck ? "<a href='javascript:void(0)' id='dData' class='fm-button ui-state-default ui-corner-all sureOn'>"+"确定"+"</a>" : "",//p.bSubmit
				bC  ="<a href='javascript:void(0)' id='eData' class='fm-button ui-state-default ui-corner-all'>"+"取消"+"</a>";//p.bCancel
				formdata += "<table border='0' class='EditTable' id='"+dtbl+"_2'><tbody><tr style='display:block;height:3px;'><td></td></tr><tr><td class='DataTD ui-widget-content'></td></tr><tr><td class='ColButton EditButton'>"+bS+"&#160;"+bC+"</td></tr></tbody></table>";
				p.gbox = "#gbox_"+gID;
				$.jgrid.createModal(IDs,formdata,p,"#gview_"+$t.p.id,$("#gview_"+$t.p.id)[0]);
				if(p.saveicon[0]==true) {
					$("#dData","#"+dtbl+"_2").addClass(p.saveicon[1] == "right" ? 'fm-button-icon-right' : 'fm-button-icon-left')
					.append("<span class='ui-icon "+p.saveicon[2]+"'></span>");
				}
				if(p.closeicon[0]==true) {
					$("#eData","#"+dtbl+"_2").addClass(p.closeicon[1] == "right" ? 'fm-button-icon-right' : 'fm-button-icon-left')
					.append("<span class='ui-icon "+p.closeicon[2]+"'></span>");
				}
				if(!p.updateAfterCheck) {
					$("#dData","#"+dtbl+"_2").click(function(e){
						for(i=0;i<$t.p.colModel.length;i++){
							if(!$t.p.colModel[i].hidedlg) { // added from T. Tomov
								var nm = $t.p.colModel[i].name.replace(/\./g, "\\.");
								if($("#col_" + nm,"#"+dtbl).prop("checked")) {//attr("checked")
									$($t).jqGrid("showCol",$t.p.colModel[i].name);
									$("#col_" + nm,"#"+dtbl).attr("defaultChecked",true); // Added from T. Tomov IE BUG
								} else {
									$($t).jqGrid("hideCol",$t.p.colModel[i].name);
									$("#col_" + nm,"#"+dtbl).attr("defaultChecked",""); // Added from T. Tomov IE BUG
								}
							}
						}
						if(p.ShrinkToFit===true) {
							$($t).jqGrid("setGridWidth",$t.grid.width-0.001,true);
						}
						if(p.closeAfterSubmit) $.jgrid.hideModal("#"+IDs.themodal,{gb:"#gbox_"+gID,jqm:p.jqModal, onClose: p.onClose});
						if (onAfterSubmit) { p.afterSubmitForm($("#"+dtbl)); }
						return false;
					});
				} else {
					$(":input","#"+dtbl).click(function(e){
						var cn = this.id.substr(4);
						if(cn){
							if(this.checked) {
								$($t).jqGrid("showCol",cn);
							} else {
								$($t).jqGrid("hideCol",cn);
							}
							if(p.ShrinkToFit===true) {
								$($t).jqGrid("setGridWidth",$t.grid.width-0.001,true);
							}
						}
						return this;
					});
				}
				$("#eData", "#"+dtbl+"_2").click(function(e){
					$.jgrid.hideModal("#"+IDs.themodal,{gb:"#gbox_"+gID,jqm:p.jqModal, onClose: p.onClose});
					return false;
				});
				$("#dData, #eData","#"+dtbl+"_2").hover(
				   function(){$(this).addClass('ui-state-hover');}, 
				   function(){$(this).removeClass('ui-state-hover');}
				);				
				if(onBeforeShow) { p.beforeShowForm($("#"+dtbl)); }
				$.jgrid.viewModal("#"+IDs.themodal,{gbox:"#gbox_"+gID,jqm:p.jqModal, jqM: true, modal:p.modal});
				if(onAfterShow) { p.afterShowForm($("#"+dtbl)); }
			}
		});
	}
});
})(jQuery);